use eframe::egui;

pub fn setup_custom_fonts(ctx: &egui::Context) {
    // Start with the default fonts (we will be adding to them rather than replacing them).
    let mut fonts = egui::FontDefinitions::default();
    // Install my own font (maybe supporting non-latin characters).
    // .ttf and .otf files supported.

    // 添加中文字体支持
    fonts.font_data.insert(
        "myfont".to_owned(),
        std::sync::Arc::new(egui::FontData::from_static(include_bytes!(
            "../assets/SourceHanSansCN-Regular.otf"
        ))),
    );

    // 将中文字体设置为首选字体
    fonts
        .families
        .get_mut(&egui::FontFamily::Proportional)
        .unwrap()
        .insert(0, "myfont".to_owned());

    // Put my font as last fallback for monospace:
    fonts
        .families
        .entry(egui::FontFamily::Monospace)
        .or_default()
        .push("myfont".to_owned());
    // Tell egui to use these fonts:
    ctx.set_fonts(fonts);
}
